import {
  Column,
  CreateDateColumn,
  Entity,
  ManyToOne,
  OneToMany,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm';
import Decimal from 'decimal.js';
import { GoodType } from '../../good-type/entities/good-type.entity';
import { Sku } from '../../sku/entities/sku.entity';
import { Spec } from '../../spec/entities/spec.entity';
import { imgDto } from '../../dto/all-dto';

@Entity()
export class Good {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({
    comment:'封面图',
    type:"json"
  })
  img: imgDto;

  @Column({
    comment: "商品名称",
    unique:true
  })
  name: string;

  @Column({
    comment: "商品描述",
    nullable: true
  })
  description: string;

  @ManyToOne(()=> GoodType, (goodType)=> goodType.children,{nullable:false})
  // @JoinColumn({ name: 'good_type_id' })  // 外键列
  goodType: GoodType;//商品所属类型

  @Column({
    comment:"规格类型 1 单规格 2多规格",
    type:'int',
    default:1
  })
  specType: number;

  @Column({
    comment:"商品状态 1上架 2下架",
    type:'int',
  })
  status: number;

  @OneToMany(()=> Sku,(sku)=> sku.good,{nullable: true})
  sku: Sku[]

  @OneToMany(()=> Spec, (data)=> data.good,{nullable:true})
  spec: Spec[]

  @CreateDateColumn()
  createTime: Date;

  @UpdateDateColumn()
  updateTime: Date;
}
